import java.util.Arrays;

/**
 * 加减法口算系统测试类
 */
public class CalculationSystemTest {

    /**
     * 测试随机数生成
     */
    public static void testRandomNumberGeneration() {
        System.out.println("=== 测试1：随机数生成 ===");
        for (int i = 0; i < 5; i++) {
            int num = CalculationSystemV03.generateRandomNumber(1, 100);
            System.out.println("随机数 " + (i+1) + ": " + num);
            assert num >= 1 && num <= 100 : "随机数超出范围";
        }
        System.out.println("随机数测试通过 ✓\n");
    }

    /**
     * 测试算式生成
     */
    public static void testEquationGeneration() {
        System.out.println("=== 测试2：算式生成 ===");

        // 测试加法
        String[] addition = CalculationSystemV02.generateEquationWithAnswer();
        System.out.println("加法算式: " + Arrays.toString(addition));

        // 测试减法
        String[] subtraction = CalculationSystemV02.generateEquationWithAnswer();
        System.out.println("减法算式: " + Arrays.toString(subtraction));

        System.out.println("算式生成测试完成 ✓\n");
    }

    /**
     * 测试重复检测功能
     */
    public static void testDuplicateDetection() {
        System.out.println("=== 测试3：重复检测 ===");

        // 生成多个算式，检查重复率
        java.util.Set<String> testSet = new java.util.HashSet<>();
        int duplicates = 0;
        int totalTests = 20;

        for (int i = 0; i < totalTests; i++) {
            String[] equation = CalculationSystemV03.generateUniqueEquationWithAnswer(0.5);
            if (equation != null) {
                String key = equation[0].replace(" = ", "");
                if (!testSet.add(key)) {
                    duplicates++;
                }
            }
        }

        double duplicateRate = (double) duplicates / totalTests * 100;
        System.out.println("测试数量: " + totalTests);
        System.out.println("重复数量: " + duplicates);
        System.out.println("重复率: " + duplicateRate + "%");

        if (duplicateRate < 10) { // 允许少量重复
            System.out.println("重复检测测试通过 ✓\n");
        } else {
            System.out.println("重复检测需要优化 ⚠\n");
        }
    }

    /**
     * 综合测试
     */
    public static void comprehensiveTest() {
        System.out.println("=== 综合测试 ===");

        System.out.println("1. 测试V0.1基础功能:");
        CalculationSystemV01.main(new String[]{});
        System.out.println();

        System.out.println("2. 测试V0.2增强功能:");
        CalculationSystemV02.main(new String[]{});
        System.out.println();

        System.out.println("3. 测试V0.3高级功能:");
        CalculationSystemV03.main(new String[]{});
    }

    public static void main(String[] args) {
        testRandomNumberGeneration();
        testEquationGeneration();
        testDuplicateDetection();
        comprehensiveTest();
    }
}
